var basePath = getBasePath(); 
var modelName = "单位/机构";
var modelLowClassName = "company";
var modelUpClassName = "Company";

$(function(){
	  //显示权限按钮
	  var parentUUID = $("input[name='parentUUID']").val();
   	  //$.permission.showButton(parentUUID,"actionBtnArea");
      loadCompanyTree();
   	  
   	  //表格初始化
	  $.dataGridEasyUI.initTable({
		  pageId:"#"+modelLowClassName+"ListPage",
		  gridId:"#"+modelLowClassName+"List",
		  url:getBasePath()+modelLowClassName+'/get'+modelUpClassName+'List.do',
		  toolbarId:"#"+modelLowClassName+"ListPage .tb_toolbar",
		  columns:[[
  		            {field:'id',checkbox:true},
  		            {field:'uuid',hidden:true},
  		            {field:'parentName',title:'上级单位',width:'12%'},
  		            {field:'companyName',title:'单位名称',width:'12%'},
  		            {field:'companyAuthority',title:'单位负责人',width:'11%'},
  		            {field:'companyPhone',title:'单位电话',width:'11%'},
  		            {field:'companyNet',title:'单位网址',width:'11%'},
  		            {field:'orderNumber',title:'排序',width:'5%'},
  		            {field:'companyRemark',title:'备注',width:'11%'},
  		            {field:'editTime',title:'编辑时间',width:'11%',formatter:function(value, row, index) {
  		            	return formatByMillisecond(value, "yyyy-MM-dd HH:mm:ss");
  					}},
  		            {field:'action',title:'操作',formatter:function(value, row, index) {
  		            	var reg=new RegExp("#ID#","g"); //创建正则RegExp对象
  		            	return $("#companyTools .row_toolbar").html().replace(reg,row.id);
  					}}
  		        ]]
	  });
  
  //新增按钮绑定事件
  $("#addDataLink").bind("click",function(){
	  $.dataGridEasyUI.initEditWindow({
		  url:getBasePath()+"manage/xtsz/edit"+modelUpClassName+".jsp",
		  title:"添加"+modelName+"信息",
		  actionType:"add"
	  });
  });
  
  //更新按钮绑定事件
  $("#updateDataLink").bind("click",function(){
	  $.dataGridEasyUI.initEditWindow({
		  url:getBasePath()+"manage/xtsz/edit"+modelUpClassName+".jsp",
		  title:"编辑"+modelName+"",
		  actionType:"update"
	  });
  });
  
  //批量删除
  $("#batchDeleteLink").bind("click",function(){
	  $.dataGridEasyUI.batchDeleteData({
		  url:getBasePath()+"/"+modelLowClassName+"/batchDel"+modelUpClassName+"ForHS.do",
	  });
  });
  
  //单个删除
  $("#singleDeleteLink").bind("click",function(){
	  $.dataGridEasyUI.batchDeleteData({
		  url:getBasePath()+"/"+modelLowClassName+"/del"+modelUpClassName+".do",
	  });
  });
})

//查看详细信息
function showDetail(id){
  $.dataGridEasyUI.initEditWindow({
	  url:getBasePath() + ""+modelLowClassName+"/get"+modelUpClassName+"Detail.do?id="+id,
	  title:"查看"+modelName+"明细",
	  actionType:"detail",
	  width: 650,
	  height: 480
  })
}

//审核信息
function checkSingleData(){
	$.dataGridEasyUI.initEditWindow({
		  url:getBasePath() + "manage/notice/checkNotice.jsp?id=",
		  title:"审核"+modelName,
		  actionType:"check",
	      width: 650,
          height: 300
	});
}

/**
 * 获取企业树数据
 * @returns
 */
function loadCompanyTree(){
	  var daohangArea = $('#companyListPage .daohangArea');
	  var url = getBasePath()+"company/getCompanyList4Tree.do"
	  daohangArea.tree({    
	        url:url,
	        method: 'post',
    		animate: true,
    		lines:true,
    		//单击某个节点触发的事件
    		onClick: function(node){
    			if(node.id!="0"){
    				$("#parentUUID").val(node.id);
    				$("#parentName").val(node.text);
    				seachData();
    			}else{
    				seachData();
    			}
    		},
    });  
}

//检索数据
function seachData(){
   var searChObj = new Object(); 
   var formId = "searchForm";
   $("#"+formId).find("input").each(function(i){
	   searChObj[$(this).attr("name")] = $(this).val();
   });
   
   $("#"+formId).find("select").each(function(i){
	   searChObj[$(this).attr("name")] = $(this).val();
   });
   tableObject.datagrid({
	     queryParams:searChObj
   })
}

//永久删除数据
function batchDelInDB(){
  $.dataGridEasyUI.batchDeleteInDB({
	  url:getBasePath()+"/"+modelLowClassName+"/batchDel"+modelUpClassName+".do",
  });
}
         
         
 //恢复数据
function rebackData(){
	$.dataGridEasyUI.batchDeleteInDB({
		  url:basePath+"/"+modelLowClassName+"/batchRebackData.do"
	});
}
